﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MapEditor
{
    public partial class frmChangeID : Form
    {
        public int ID {get;set;}
        private Dictionary<int, int> dict;

        public frmChangeID( Dictionary<int, int> dict)
        {
            InitializeComponent();
            this.dict = dict;
        }

        private void btnChange_Click(object sender, EventArgs e)
        {
            int validateInt;
            if (int.TryParse(txtID.Text, out validateInt))
            {
                ID = validateInt;

                if (ValidateKey(ID))
                    this.DialogResult = DialogResult.Yes;
                else
                    MessageBox.Show("Clef déjà utiliser");
            }
            else
                MessageBox.Show("Vous devez Entrer un nombre (ID)");
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
        }

        private bool ValidateKey(int Keysvalue)
        {
            for (int i = 0; i < dict.Count(); i++)
            {
                if (dict[i] == Keysvalue)
                    return false;
            }
            return true;
        }

       

      
    }
}
